Feat/scmi 124866 [Domain models initiative] private attribute lint rule#1789
Feat/scmi 124866 [Domain models initiative] private attribute lint rule#1789aleixadevinta wants to merge 9 commits intomasterfrom
Conversation
|
|
||
| // Check if a private attribute has a public accessor | ||
| const privateAttributes = node.body.body.filter(node => { | ||
| return node.type === 'PropertyDefinition' && node.key.type === 'PrivateIdentifier' |
There was a problem hiding this comment.
I'm not sure if this code will get attributes starting with a # and with a _. Those two ways, are common in javascript to declare an attribute as private.
This suggestion implies also to methods.
There was a problem hiding this comment.
We decided in the agreement that all private attributes will be defined by #, as it is the native way to define private attributes in the latest versions of ECMAScript.
| const existNativeGetterWithAttributeKey = method.key.name === attribute.key.name && method.kind === 'get' | ||
| const existCustomGetterWithAttributeKey = method.key.name === customGetterName | ||
|
|
||
| if (existNativeGetterWithAttributeKey | existCustomGetterWithAttributeKey) { |
There was a problem hiding this comment.
I'm not sure if the condition is well, it's intentionally with one | or should it be ||?
| if (existNativeGetterWithAttributeKey | existCustomGetterWithAttributeKey) { | |
| if (existNativeGetterWithAttributeKey || existCustomGetterWithAttributeKey) { |
| ClassDeclaration(node) { | ||
| const className = node?.id?.name ?? '' | ||
|
|
||
| const allowedWords = ['VO', 'ValueObject', 'Entity'] |
There was a problem hiding this comment.
This is a good approach and this rule will cover a lot of cases, but it will not check classes without names but under the correct place (valueObjects or entities folders).
To achieve that, with the lines below, you can check if the file is inside those folders and run this rule inside them too.
const filePath = context.getFilename()
const relativePath = path.relative(context.getCwd(), filePath)
// Check if the file is inside the requierd folders (entities, services, repositories, ...)
const entitiesPattern = /entities|Entities/i
const isEntityPath = entitiesPattern.test(relativePath)
// ... same with value objectsSee this PR lines, and follow the code to understand.
I suggest you detect different cases in our code base and run it there to see if this rule is working fine in different scenarios.

Description
In this pull request we ensure that a doamin model class (value object or entity) has all attributes as private and each attribute has his getter.
Related Issue
SCMI-124866